<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  
</head>
<body>
  <div id="app">
    <input type="text" v-model="msg">
    {{ msg }}
    <hr>
    侦听对象
    a
    <input type="text" v-model="obj.a">
    b
    <input type="text" v-model="obj.b">
    {{ obj.a }}
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        msg: '',
        obj: {
          a: 10,
          b: 20
        }
      },
      watch: {
        msg(newVal, oldVal){
          console.log(newVal, '新值');
          console.log(oldVal, '旧值');
        },
      /*   obj(newVal){
          console.log('值改变了');
        } */
        /* "obj.a"(newVal){
          console.log(newVal);
        }, */
        // 直接侦听对象
        obj: {
          handler(newVal){
            console.log(newVal, '侦听对象');
          },
          deep: true // 深度监听
        }
      }
    })
  </script>
</body>
</html>